﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ChampionFramework.Models;

namespace ChampionFramework.Controllers
{
	public class CartaoController : BaseEventoController<Cartao>
	{
		private ChampionContextContainer db = new ChampionContextContainer();

		//
		// GET: /Cartao/

		public ActionResult Index()
		{
			var eventoset = db.EventoSet.Include("Jogador");
			return View(eventoset.OfType<Cartao>().ToList());
		}

		//
		// GET: /Cartao/Details/5

		public ActionResult Details(int id = 0)
		{
			Cartao cartao = (Cartao)db.EventoSet.Single(c => c.Id == id);
			if (cartao == null)
			{
				return HttpNotFound();
			}
			return View(cartao);
		}

		//
		// GET: /Cartao/Create
        /*
		public ActionResult Create()
		{
			ViewBag.JogadorId = new SelectList(db.JogadorSet, "Id", "Nome");
			return View();
		}

		//
		// POST: /Cartao/Create

		[HttpPost]
		public ActionResult Create(Cartao cartao)
		{
			if (ModelState.IsValid)
			{
				db.EventoSet.AddObject(cartao);
				db.SaveChanges();
				return RedirectToAction("Index");
			}

			ViewBag.JogadorId = new SelectList(db.JogadorSet, "Id", "Nome", cartao.JogadorId);
			return View(cartao);
		}
        */
		//
		// GET: /Cartao/Edit/5

		public ActionResult Edit(int id = 0)
		{
			Cartao cartao = (Cartao)db.EventoSet.Single(c => c.Id == id);
			if (cartao == null)
			{
				return HttpNotFound();
			}
			ViewBag.JogadorId = new SelectList(db.JogadorSet, "Id", "Nome", cartao.JogadorId);
			return View(cartao);
		}

		//
		// POST: /Cartao/Edit/5

		[HttpPost]
		public ActionResult Edit(Cartao cartao)
		{
			if (ModelState.IsValid)
			{
				db.EventoSet.Attach(cartao);
				db.ObjectStateManager.ChangeObjectState(cartao, EntityState.Modified);
				db.SaveChanges();
				return RedirectToAction("Index");
			}
			ViewBag.JogadorId = new SelectList(db.JogadorSet, "Id", "Nome", cartao.JogadorId);
			return View(cartao);
		}

		//
		// GET: /Cartao/Delete/5

		public ActionResult Delete(int id = 0)
		{
			Cartao cartao = (Cartao)db.EventoSet.Single(c => c.Id == id);
			if (cartao == null)
			{
				return HttpNotFound();
			}
			return View(cartao);
		}

		//
		// POST: /Cartao/Delete/5

		[HttpPost, ActionName("Delete")]
		public ActionResult DeleteConfirmed(int id)
		{
			Cartao cartao = (Cartao)db.EventoSet.Single(c => c.Id == id);
			db.EventoSet.DeleteObject(cartao);
			db.SaveChanges();
			return RedirectToAction("Index");
		}

		protected override void Dispose(bool disposing)
		{
			db.Dispose();
			base.Dispose(disposing);
		}
	}
}